package cn.itcast.mq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * 声明队列
 *
 * @Author mr.wu
 * @Date 2025/1/5 11:08
 */
@Configuration
public class RabbitConfig {
    @Bean
    public Queue simpleQueue() {
        return new Queue("simple.queue", true);
    }
    @Bean
    public Queue simpleQueue2() {
        return new Queue("Work.queue", true);
    }

    /**
     * 广播模型-fanout-交换机
     */
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout.exchange");
    }

    /**
     * 广播模型-fanout-队列1
     */
    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1");
    }

    /**
     * 广播模型-fanout-队列2
     */
    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2");
    }

    /**
     * 绑定队列和交换机1
     */
    @Bean
    public Binding bingFanoutQueue1(Queue fanoutQueue1, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }

    /**
     * 绑定队列和交换机2
     */
    @Bean
    public Binding bingFanoutQueue2(Queue fanoutQueue2, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue2).to(fanoutExchange);
    }

    /**
     * 消息转换器-默认转换器
     */
    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue");
    }

}
